package com.xfly.app.ui;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;

import com.ptmall.app.R;
import com.ptmall.app.base.BaseMvpActivity;
import com.ptmall.app.net.api.ApiDataRepository;
import com.ptmall.app.net.base.ApiNetResponse;
import com.ptmall.app.view.TitleBarView;
import com.xfly.app.adapter.YfAdapter;
import com.xfly.app.bean.HdBean;
import com.xfly.app.bean.LbBean;
import com.xfly.app.bean.YfBean;

import java.util.ArrayList;
import java.util.List;

public class YfActivity extends BaseMvpActivity {

    TitleBarView title_bar;

    LinearLayout add;

    YfAdapter yfAdapter;

    List<YfBean> list = new ArrayList<>();
    TextView price;
    ApiDataRepository apiDataRepository = ApiDataRepository.getInstance();

    ListView listview;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setView(R.layout.activity_yf);
    }

    @Override
    public void initViews() {
        title_bar = findViewById(R.id.title_bar);
        price = findViewById(R.id.price);
        listview = findViewById(R.id.listview);
        add = findViewById(R.id.add);


    }

    @Override
    public void initEvents() {
        title_bar.setText("运费设置");
        title_bar.setRightText("修改");
        title_bar.setOnTitleBarClickListener(new TitleBarView.TitleBarClickListener() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {
                startActivity(new Intent(getContext(),YfSetActivity.class));
            }
        });
        add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {

            }
        });
        yfAdapter = new YfAdapter(getContext(),list);
        listview.setAdapter(yfAdapter);

        getyf();
    }

    private void getyf(){
        apiDataRepository.getyf(null, new ApiNetResponse<List<YfBean>>() {
            @Override
            public void onSuccess(List<YfBean> data) {
                list = data;
                yfAdapter.pushData(list);
//                if(list.size()>0){
                    add.setVisibility(View.GONE);
//                }
            }
        });
        apiDataRepository.gethd(null, new ApiNetResponse<HdBean>() {
            @Override
            public void onSuccess(HdBean data) {
                price.setText("￥"+data.postage);
            }
        });
    }
}
